package com.kfm.servlet.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/get")
public class CookieGetServlet2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取 cookie
        Cookie[] cookies = req.getCookies();
        // 遍历 cookies
        for (Cookie cookie : cookies) {
            // 输出 cookie 的 name 和 value
            System.out.println(cookie.getPath() + " = " + cookie.getName() + " : " + cookie.getValue());
        }
    }
}
